package com.sl.au.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sl.au.entity.Account;
import com.sl.au.service.AccountService;
import com.sl.au.service.MobileMessageSend;
/***
 * 短信验证-网易云
 * @author chuck
 *
 */
@RestController
@RequestMapping(value = "/ui/loginmessage")
public class LoginMessageController extends BaseController{
	
	@Autowired
	private MobileMessageSend mobileMessageSend;
	
	@Autowired
	private AccountService accountService;
	
	
	/***
	 * 请求发送验证码
	 * @return
	 */
	@RequestMapping(value = "sendMessage/{userName}", method = RequestMethod.GET)
	Map<String, Object> SMS(@PathVariable String userName) {
		Map<String, Object> map = new HashMap<>();
		int code = 0;
		String result = "";
		Account account = accountService.getAccountData(userName);
		String phoneNumber = "";
		boolean isFindAcc = false;
		if(account != null){//账户不存在
			if(account.getUser() != null && account.getUser().getContactType() != null 
					&& account.getUser().getContactType() != ""){//账户存在并且电话号码不为空
				isFindAcc = true;
				phoneNumber = account.getUser().getContactType();
			}else{
				code = 1;
				result = "账户信息错误!";
			}
		}else{
			code = 1;
			result = "账户错误!";
		}
		if(isFindAcc){
//			try {
//				result = mobileMessageSend.sendMsg(phoneNumber);
//			} catch (IOException e) {
//				code = 1;
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
		}
		
		map.put("result", result);
		map.put("code", code);	
		return map;
	}
}
